// 城市id
let id = localStorage.getItem('id')
// 城市数据
let city = JSON.parse(localStorage.getItem('data'))
// 价钱
let price = JSON.parse(localStorage.getItem('price'))
// 获取朝向
let cx = JSON.parse(localStorage.getItem('cx'))
// 获取城市地区
if (city) {
    city.forEach(function (item) {
        if (item.value == id) {
            let module = `<a href="./city copy.html"style="color: white">${item.label}</a>`
            $('.spn1').append(module)
        }
    })
    price.forEach(function(item){
        let module1 = `
             <option value="">${item.price}</option>
        `
        $('#se2').append(module1)
    })
    cx.forEach(item=>{
        let module = `
            <option value="">${item.desc}</option>
        `
        $('#se3').append(module)
    })
} else {
    let module = `<a href="./public/city.html">选择地区</a>`
    $('.spn1').append(module)
}


// 城市下属地区数据
citys()
function citys() {
    let ids = localStorage.getItem('id')
    $.ajax({
        type: "get",
        url: "http://localhost:8081/area/map",
        data: {
            id: ids
        },
        success: function (res) {
            let data = res.body
            data.forEach(item => {
                let module = `
                <option class="opt" value="${item.label}">${item.label}</option>
                `
                $('.se1').append(module)
            })
            // 点击获取城市value
            $(".se1").change(function () {
                areas($(this).val())
            })
        }
    });
}



// 地图api
areas('北京')
function areas(val) {
    var map = new BMapGL.Map('container');
    map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 7);
    map.enableScrollWheelZoom();
    var zoomCtrl = new BMapGL.ZoomControl();
    map.addControl(zoomCtrl);

    // --- 添加行政区划 ---
    var dist = new BMapGL.DistrictLayer({
        name: `(${val})`,
        kind: 1,
        fillColor: '#618bf8',
        fillOpacity: .5,
        strokeColor: '#daeafa',
        viewport: true
    });
    map.addDistrictLayer(dist);

    // 绘制圆
    var circle = new BMapGL.Circle(new BMapGL.Point(116.404, 39.915), 500, {
        strokeColor: 'blue',
        strokeWeight: 2,
        strokeOpacity: 0.5
    });
    map.addOverlay(circle);

    // --- 行政区划添加鼠标事件 ---
    dist.addEventListener('mouseover', function (e) {
        e.currentTarget.setFillColor('#9169db');
    });
    dist.addEventListener('mouseout', function (e) {
        e.currentTarget.setFillColor(e.currentTarget.style.fillColor);
    });
}